package com.shujia.spark.core

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Demo5FlatMap {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf()
    conf.setAppName("Demo5FlatMap")
    conf.setMaster("local")

    val sc = new SparkContext(conf)

    val linesRDD: RDD[String] = sc.textFile("data/words.txt")

    /**
     * flatMap:一条一条将RDD的数据传递给后面的函数，函数的返回值必须是一个集合，最后会将集合展开构建成一个新的RDD
     * 传入一行返回多行
     *
     */
    val wordsRDD: RDD[String] = linesRDD.flatMap(line => line.split(","))

    wordsRDD.foreach(println)
  }

}
